#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File  : settings.py
@Author: different && 道阻且长,行则将至 行而不辍,未来可期
@Date  : 2021/08/03
@Desc  : 配置文件

"""
import random
import string
from pathlib import Path

from flask_script import Server

# 项目路径
BASE_DIR = Path(__file__).resolve().parent

# 上传文件保存路径
UPLOAD_FOLDER = BASE_DIR / "uploader"
ALLOWED_EXTENSIONS = {"xlsx", "xls"}

HOST_IP = "192.168.6.126"
PORT = 5001

SERVER = Server(host=HOST_IP, port=PORT)

# 数据库 MySQL

DB_MYSQL = {
    "host": "47.112.235.228",
    "user": "bi",
    "passwd": "Mysql8_bi_password",
    "port": 6033,
    "db": "survey_db",
    "charset": "utf8"
}

DB_MYSQL_ENV = {
    "host": "rm-wz9zwd01zsa8i16seto.mysql.rds.aliyuncs.com",
    "user": "zzw",
    "passwd": "Zz5217cc",
    "port": 3306,
    "db": "survey_db",
    "charset": "utf8"
}


def db_config(config):
    return f"""mysql+pymysql://{config["user"]}:{config["passwd"]}@{config["host"]}:{config["port"]}/{config["db"]}?charset={config["charset"]}"""


# 生产环境默认配置
class Config(object):
    """Base config, uses staging database server."""
    TESTING = False
    SECRET_KEY = "y&2z+qndy)qg6wr%6#wi4ls$6!w9wyc!j_4z-&0di!rrtcky26"

    # ORM底层所访问数据库URI

    # 当关闭数据库是否自动提交事务
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # 是否追踪修改
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 调试设置为true
    SQLALCHEMY_ECHO = False

    CACHE_TYPE = "SimpleCache"  # Flask-Caching related configs
    CACHE_DEFAULT_TIMEOU = 300


# 测试或开发环境继承Config类，重写相关配置项
class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = db_config(DB_MYSQL)


class DevelopmentConfig(Config):
    ENV = "development"
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = db_config(DB_MYSQL_ENV)


class TestConfig(Config):
    ENV = "testing"
    TESTING = True
    SQLALCHEMY_DATABASE_URI = db_config(DB_MYSQL_ENV)


# 设置配置映射
setting = {
    "production": ProductionConfig,
    "development": DevelopmentConfig,
    "test": TestConfig,
    "default": DevelopmentConfig
}

TITLE_MAP = {
    "ASIN": "asin",
    "站点": "site",
    "产品链接": "product_link",
    "主图地址": "image_url",
    "视频": "video_link",
    "所在页数": "page_num",
    "页面排名": "page_rank",
    "广告所在页数": "ad_page_num",
    "广告页面排名": "ad_page_rank",
    "价格": "price",
    "变体": "variants",
    "跟卖数": "follow_up",
    "A+": "aPlus",
    "上架日期": "shelf_date",
    "大类目": "big_category",
    "大类目排名": "big_category_rank",
    "小类目1": "sub_category_1",
    "小类目1排名": "sub_category_1_rank",
    "小类目2": "sub_category_2",
    "小类目2排名": "sub_category_2_rank",
    "近30天排名": "rank_days_30",
    "ratings": "ratings",
    "评分": "rating",
    "reviews": "reviews",
    "Critical": "critical",
    "VP评论数": "vp_comments",
    "QA数": "qa_num",
    "品牌": "brand",
    "卖家类型": "seller_type",
    "店铺名称": "store_name",
    "feedback数": "feedback_num",
    "feedback差评率": "feedback_rate",
    "销量": "sale"
}
